package com.xinfan.io.writer;

import org.junit.jupiter.api.Test;

import java.io.FileWriter;
import java.io.IOException;

/**
 * @Author xin
 * @Date 2022/6/8 16:41
 * @Version 1.0
 */
public class FileWriter_ {


    @Test
    public void writer() {
        String des = "G:\\桌面\\out.txt";
        FileWriter fileWriter = null;

        try {
            fileWriter = new FileWriter(des,true);//叠加模式
            //写入单字符
            fileWriter.write('H');//H
            //写入字符数组
            fileWriter.write(new char[]{'a', 'b'});//ab
            //写入自定义长度字符串
            fileWriter.write(des.toCharArray(),0,2);//G:
            //写入字符串
            fileWriter.write(des);//G:\桌面\out.txt

            //写入自定义长度字符串
            fileWriter.write(des,0,5);//G:\桌面

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
